<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Adminlog Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Debts_model extends MY_Model{
	
	public function __construct(){
		parent::__construct();
		$this->table_name = 'book_debts';
	}
        
        public function insertDebtsInfo($params){
                $this->debts_model->create($params);
                $result = $this->db->affected_rows();
                if(!$result){
                    die("Insert db ".$this->table_name.' fail!');
                }
                return $result;
        }
        
        public function selectAll(){
            $this->db->select('*');
            $this->db->from($this->table_name);
            $query = $this->db->get();
            return $query->result();
        }
        
        public function selectListUnActive(){
            $this->db->select('count(*) AS count');
            $this->db->from($this->table_name);
            $this->db->where('payment_confirm', '0');
            $query = $this->db->get();
            
            return $query->result();
        }
        
        public function udpate_confirm($params){
            $sql    = "UPDATE {$this->table_name} SET payment_confirm = 1, lastupdated = '".time()."' WHERE customerID = '".$params."'";
            $this->db->query($sql);
            return $this->db->affected_rows();
        }
}